<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>川农车辆预约系统</title>
		<meta name="viewport" content="width=device-width, initial-scale=1" charset="utf-8">
		<link rel="stylesheet" href="../css/bootstrap-3.3.7-dist/css/bootstrap.css">
		<link rel="stylesheet" href="../css/body.css" />
		<link rel="stylesheet" href="../css/dividePage.css">
		<script src="../js/jQuery.js"></script>
		<script src="../css/bootstrap-3.3.7-dist/js/bootstrap.js"></script>
		<script src="../js/index.js"></script>
		<script src="../js/dividePage.js"></script>
		<script src="../js/onload.js"></script>
		<!--	页面需要加载两次才能正常运行，千万别删！-->
		<script>
			if(sessionStorage.res == 0){
				sessionStorage.res = 1;
				// user_login();
				window.location.reload();
			}
		</script>

	</head>

	<body>
		<!--首页初始导航条-->
		<nav class="navbar navbar-inverse navbar-fixed-top">
			<div class="container">
				<div class="navbar-header">
					<span class="navbar-brand logo1">川农车辆预约系统</span>
					<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#m1">
						<span class="icon-bar"></span>
						<span class="icon-bar"></span>
						<span class="icon-bar"></span>
					</button>
				</div>
				<div class="navbar-collapse collapse" id="m1">
					<ul class="nav navbar-nav navbar-left">
						<li class="active">
							<a href="../index/index.html"><span class="glyphicon glyphicon-home"></span>&nbsp;首页</a><!--这里的span是设置bootstrap字体图标类-->
						</li>
						
						<!--一个下拉菜单-->
						<!--<li class="dropdown">
							<a href="#" class="dropdown-toggle" data-toggle="dropdown">
								长期车辆申请
								<b class="caret"></b>
							</a>
							<ul class="dropdown-menu">
								<li>
									<a href="../index/fileDownload.html">表单下载</a>
								</li>
								<li>
									<a href="../index/longResults.html">结果公示</a>
								</li>
							</ul>
						</li>-->
					</ul>
					
					<div class="nav navbar-nav navbar-right" id="loginWho">
						<!-- <li><a href="../index/login.html">登陆</a></li> -->
						<!-- <li class="dropdown"><a href="login.html" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">登陆<span class="caret"></span></a><ul class="dropdown-menu"><li><a href="http://113.54.11.32/cars/public/index.php/user/user/login">用户登录</a></li><li><a href="login.html">管理员登录</a></li></ul></li> -->

						<!-- <li class="dropdown">
          					<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">登陆<span class="caret"></span></a>
          					<ul class="dropdown-menu">
					            <li><a href="https://carorder.sicau.edu.cn/login/loginIn">用户登录</a></li>
					            <li><a href="login.html">管理员登录</a></li></ul></li>
							</ul>
        				</li> -->
					</div>
				</div>
			</div>
		</nav>

		<div id="article" class="container-fluid">
			<!--公告内容-->
		</div>
		<div class="pageDiv" id="pageDiv"></div>

		<footer class="container-fluid foot-wrap">
		    <div>
		        <p align="center" style="margin-top: 20px;color:#878B91;">
		            若有其它疑问或特殊情况，请及时与我们联系。（雅安校区：一舍  0835-2883011；成都校区：一教115  028-86291000）
		        </p>
		        <p align="center" style="margin-top: 20px;color:#878B91;">
		        	Copyright &copy;2019 
		        </p>
		    </div>
		</footer>
   	

	<script type="text/javascript">
	index_get()
	function changePage(e){
				nowPage = e.getAttribute("value");
				$("#article").empty();
				var data3;
				var tbody = "";
						$.ajax({
							type: "GET",
							url: "https://carorder.sicau.edu.cn/adminCar/showNotice",
							dataType: "text", //后台返回格式问题
							data:{
								page:nowPage,
								pageSize:5,	
							},
							success: function(data) {
								data1 = eval('(' + data + ')'); 
								if(data1.total%5 == 0){
									sessionStorage.allPage = parseInt(data1.total/5);
								}else{
									sessionStorage.allPage = parseInt(data1.total/5+1);
								}								
								if(sessionStorage.user == 1){
									jQuery.each(data1.result,function(i, value) {
										var content = value.content; 
										var trs = '<div class="container things"><h3>' + value.title + `</h3><button onclick=deleteNotice(this) value=${value.id}>删除</button><p><small>发布时间：` + value.time + '</small></p><p>' + content + '</p></div>';
										tbody += trs;
									});
									$("#article").append(tbody);
								}else{
									jQuery.each(data1.result,function(i, value) {
										var content = value.content; 
										var trs = '<div class="container things"><h3>' + value.title + '</h3><p><small>发布时间：' + value.time + '</small></p><p>' + content + '</p></div>';
										tbody += trs;
									});
									$("#article").append(tbody);
								}
							},
							error: function(data) {
								alert("接收失败,code:" + data.status);
							}
				});
	}
	function jumpPage(){
	var searchId = $("#pageNum")
	nowPage = searchId[0].value
				$("#article").empty();
				var data3;
				var tbody = "";
						$.ajax({
							type: "GET",
							url: "https://carorder.sicau.edu.cn/adminCar/showNotice",
							dataType: "text", //后台返回格式问题
							data:{
								page:searchId[0].value,
								pageSize:5,	
							},
							success: function(data) {
								data1 = eval('(' + data + ')'); 
								if(data1.total%5 == 0){
									sessionStorage.allPage = parseInt(data1.total/5);
								}else{
									sessionStorage.allPage = parseInt(data1.total/5+1);
								}
								if(sessionStorage.user == 1){
									jQuery.each(data1.result,function(i, value) {
										var content = value.content; 
										var trs = '<div class="container things"><h3>' + value.title + `</h3><button onclick=deleteNotice(this) value=${value.id}>删除</button><p><small>发布时间：` + value.time + '</small></p><p>' + content + '</p></div>';
										tbody += trs;
									});
									$("#article").append(tbody);
								}else{
									jQuery.each(data1.result,function(i, value) {
										var content = value.content; 
										var trs = '<div class="container things"><h3>' + value.title + '</h3><p><small>发布时间：' + value.time + '</small></p><p>' + content + '</p></div>';
										tbody += trs;
									});
									$("#article").append(tbody);
								}
							},
							error: function(data) {
								alert("接收失败,code:" + data.status);
							}
				});
}
	function deleteNotice(e){
		var id = e.getAttribute("value");
		$.ajax({
			type: "POST",
			url: "https://carorder.sicau.edu.cn/adminCar/deleteNotice",
			beforeSend: function (xhr) {
				xhr.setRequestHeader("token", sessionStorage.token);
			},
			dataType: "text", //后台返回格式问题
			data:{
				id:id,
			},
			success: function(data) {
				alert("删除成功");
				window.location = "../index/index.html";
			},
			error: function(data) {
				alert("删除失败");
				window.location = "../index/index.html";
			}
		}); 
		}
	</script>
	</body>
	<script type="text/javascript" src="../js/judge.js"></script>
</html>